<?php

/**
 * 后台上传手机图片
 */
class AppController extends AdminBase {

    public function actionIndex() {
        
    }

    /**
     * 更新app首页图片
     */
    public function actionStartpic() {
        $model = new AppStartpicModel();
        if (IS_POST) {
             $url = Yii::app()->request->getParam('url');
            $picInfo = $model->getPicInfo();
            $model->setValidators($model->rules);
            // print_r($picInfo);exit;          
            $model->attributes = $picInfo[0];
            $model->url = $url;
            if ($model->validate() && $model->save()) {
                $this->success('更新成功！', self::U('startpic'));
            } else {
                $this->error(UploadFile::getInstance()->getError() ? UploadFile::getInstance()->getError() : '更新失败,请重新上传！');
            }
        } else {
            $this->render();
        }
    }
    public function actionAdpic(){
         $model = new AppStartpicModel();
        if (IS_POST) {
            $url = Yii::app()->request->getParam('url');
            $picInfo = $model->getPicInfo();
            $model->setValidators($model->rules);
            // print_r($picInfo);exit;          
            $model->attributes = $picInfo[0];
            $model->url = $url;
            if ($model->validate() && $model->save()) {
                $this->success('更新成功！', self::U('adpic'));
            } else {
                $this->error(UploadFile::getInstance()->getError() ? UploadFile::getInstance()->getError() : '更新失败,请重新上传！');
            }
        } else {
            $this->render();
        }
    }

    /**
     * 展示上传图片管理
     */
    public function actionDisplay() {
        $model = new AppStartpicModel();
        $criteria = $model->where(array('order' => 'platform desc'));
        $data = $model->findAll($criteria);
        $list = array();
        foreach ($data as $key => $pagedata) {
            $list[$key] = $pagedata->attributes;
            $list[$key]['aid'] = $pagedata->aid;
            $list[$key]['platform'] = $pagedata->platform;
            $list[$key]['filepath'] = $pagedata->filepath;
            $list[$key]['uploadtime'] = $pagedata->uploadtime;
            $list[$key]['picname'] = $pagedata->picname;
        }
        $this->render('display', array('list' => $list));
    }

    /**
     * 删除图片
     */
    public function actionDelete() {
        $model = new AppStartpicModel();
        $aid = Yii::app()->request->getParam('aid');
        if ($model->deletePic($aid)) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败！');
        }
    }

}
